package org.come.npc;

import org.come.Jpanel.FrameMessageChangeJpanel;
import org.come.action.NpcMenuAction;
import org.come.bean.PrivateData;
import org.come.bean.Skill;
import org.come.until.AnalysisString;
import org.come.until.SendRoleAndRolesummingUntil;
import org.come.until.UserMessUntil;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;

/**
 * 技能学习
 * @author Administrator
 *
 */
public class SkillLearn implements NpcMenuAction{

	@Override
	public void menuControl(String type) {
		if (type==null|| "".equals(type)) {return;}
		Skill skill=UserMessUntil.getskill1(type);
		if (skill==null) {return;}
		PrivateData data=RoleData.getRoleData().getPrivateData();
		String[] vs=data.getSkill("S");
		if (vs!=null) {
			for (int i = 0; i < vs.length; i++) {
				if (vs[i].startsWith(skill.getSkillid())) {
					FrameMessageChangeJpanel.addtext(5,"你已经学会了该技能",null,null);
					return;
				}
			}
		}
		int id =Integer.parseInt(skill.getSkillid());
		int lvl=Integer.parseInt(skill.getSkilllevel());
		int leixing=learnlimit(id,lvl,vs);
		if (leixing==0) {
			StringBuffer buffer=new StringBuffer();
			if (vs!=null) {
				for (int i = 0; i < vs.length; i++) {
					if (buffer.length()!=0) {buffer.append("#");}
					buffer.append(vs[i]);
				}
			}
			if (buffer.length()!=0) {buffer.append("#");}
			buffer.append(id);
			buffer.append("_");
			int sld = AnalysisString.shuliandu(ImageMixDeal.userimg.getRoleShow().getGrade());
			buffer.append(sld);
			data.setSkills("S",buffer.toString());
			SendRoleAndRolesummingUntil.sendRole(data);
			FrameMessageChangeJpanel.addtext(5,"你学会了"+skill.getSkillname(),null,null);
		}else if (leixing==2){
			FrameMessageChangeJpanel.addtext(5,"你还不够火候学习当前技能",null,null);
		}else if (leixing==1){
			FrameMessageChangeJpanel.addtext(5,"年轻人不要好高骛远,先去学习上一个技能!",null,null);
		}
	}
	/**判断是否能学习当前技能0可以学习1未学习前置技能 2熟练度不够*/
	public int learnlimit(int id,int lvl,String[] vs){
		if (lvl==1) {return 0;}
		String qzid=(id-1)+"";
		for (int i = 0; i < vs.length; i++) {
			if (vs[i].startsWith(qzid)) {
				if (Integer.parseInt(vs[i].split("_")[1])>1000) {
					return 0;
				}else {
					return 2;
				}
			}
		}
		return 1;
	}
}
